package com.itheima.kehuduanfuwuqi;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws Exception {
        //创建客户端Socket对象
        Socket socket = new Socket("127.0.0.1", 10010);

        //创建缓冲字节输入流对象
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\study\\就业班\\4.jpg"));
        //创建缓冲字节输出流对象
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        //网络输出
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }
        //网络输出必须刷新
        bos.flush();
        //指定传输结束标记
        socket.shutdownOutput();

        //创建接收反馈缓冲输入字符流
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        //接收反馈
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);

            //释放资源    }
            bis.close();
            socket.close();
        }
    }
}
